<template>
  <div class="netdisk-container">
    <!-- 使用AppHeader组件替代原来的导航栏 -->
    <AppHeader functionName="云檐藏阁" theme="light" maxWidth="100%"></AppHeader>
    <el-container class="main-container">
      <!-- 侧边栏导航 -->
      <el-aside width="200px" class="netdisk-aside">
        <el-menu class="netdisk-menu" :default-active="activeMenu" background-color="transparent" text-color="#303133"
          active-text-color="#3578e5" :default-openeds="defaultOpeneds" router>
          <!-- 常用菜单项单独显示 -->
          <el-menu-item index="/file/explorer" class="menu-item">
            <div class="menu-content">
              <el-icon>
                <Document />
              </el-icon>
              <span>全部文件</span>
            </div>
          </el-menu-item>

          <!-- 分类 -->
          <el-sub-menu index="category">
            <template #title>
              <div class="menu-content">
                <el-icon>
                  <FolderOpened />
                </el-icon>
                <span>文件分类</span>
              </div>
            </template>
            <div class="submenu-container">
              <el-menu-item index="/file/explorer?fileType=image">
                <div class="submenu-content">
                  <el-icon>
                    <Picture />
                  </el-icon>
                  <span>图片</span>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/explorer?fileType=video">
                <div class="submenu-content">
                  <el-icon>
                    <VideoPlay />
                  </el-icon>
                  <span>视频</span>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/explorer?fileType=word">
                <div class="submenu-content">
                  <el-icon>
                    <Files />
                  </el-icon>
                  <span>文档</span>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/explorer?fileType=audio">  
                <div class="submenu-content">
                  <el-icon>
                    <Collection />
                  </el-icon>
                  <span>音乐</span>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/explorer?fileType=zip">  
                <div class="submenu-content">
                  <el-icon>
                    <Box />
                  </el-icon>
                  <span>压缩包</span>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/explorer?fileType=other">  
                <div class="submenu-content">
                  <el-icon>
                    <More />
                  </el-icon>
                  <span>其他</span>
                </div>
              </el-menu-item>
            </div>
          </el-sub-menu>

          <!-- 传输记录 -->
          <el-sub-menu index="transfer">
            <template #title>
              <div class="menu-content">
                <el-icon>
                  <Connection />
                </el-icon>
                <span>传输管理</span>
              </div>
            </template>
            <div class="submenu-container">
              <el-menu-item index="/file/upload-record">
                <div class="submenu-content">
                  <div class="submenu-left">
                    <el-icon>
                      <Upload />
                    </el-icon>
                    <span>上传记录</span>
                  </div>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/download-record">
                <div class="submenu-content">
                  <div class="submenu-left">
                    <el-icon>
                      <Download />
                    </el-icon>
                    <span>下载记录</span>
                  </div>
                </div>
              </el-menu-item>
              <el-menu-item index="/file/share">
                <div class="submenu-content">
                  <el-icon>
                    <Share />
                  </el-icon>
                  <span>我的分享</span>
                </div>
              </el-menu-item>
            </div>
          </el-sub-menu>

          <!-- 回收站放在最后 -->
          <el-menu-item index="/netdisk/trash" class="menu-item">
            <div class="menu-content">
              <el-icon>
                <Delete />
              </el-icon>
              <span>回收站</span>
            </div>
          </el-menu-item>

          <!-- 存储空间信息 -->
          <div class="storage-info-wrapper">
            <div class="storage-info">
              <el-progress :percentage="storageUsage" :format="formatStorage" :stroke-width="8" />
              <div class="storage-text">
                <span>{{ usedStorage }}GB / {{ totalStorage }}GB</span>
              </div>
            </div>
          </div>
        </el-menu>
      </el-aside>

      <!-- 主要内容区域 -->
      <el-main class="netdisk-main">
        <NuxtPage />
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import { ref, onMounted } from 'vue'
import { Document, Folder, Picture, VideoPlay, Delete, Star, Grid, List, Download, Share, More, Collection, FolderAdd, Plus, Files, Headset, Upload, Menu, FolderOpened, Box, Connection, Fold, Expand, ArrowDown, ArrowRight } from '@element-plus/icons-vue'

const route = useRoute()
// 当前激活的菜单
const activeMenu = ref('/netdisk/file-explorer')
// 默认展开的子菜单
const defaultOpeneds = ref(['category', 'transfer'])
// 存储空间使用情况数据
const usedStorage = ref(2.56)
const totalStorage = ref(10)
const storageUsage = ref(Math.floor((usedStorage.value / totalStorage.value) * 100))
// 格式化存储空间显示
const formatStorage = (percentage) => {
  return `已用 ${percentage}%`
}
// 根据当前路由更新激活菜单
onMounted(() => {
  activeMenu.value = route.path

  // // 如果是首次访问网盘页面，重定向到全部文件页面
  // if (route.path === '/netdisk' || route.path === '/netdisk/') {
  //   router.push('/netdisk/all-files')
  // }
})
</script>

<style lang="scss" scoped>
.netdisk-container {
  height: 100vh;
  display: flex;
  flex-direction: column;

  // 背景调整为纯白色
  background-color: #ffffff;
}

.netdisk-header {
  background-color: #fff;
  box-shadow: inset 0px -1px 0px rgba(0, 0, 0, 0.1), 0px 2px 12px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 60px;
  border-bottom: 1px solid #e0e0e0;

  .left-section {
    display: flex;
    align-items: center;

    .logo {
      width: 36px;
      height: 36px;
      background-color: #f0f2f5;
      border-radius: 10px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 22px;
      font-weight: bold;
      color: #3370ff;
      box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
      transition: all 0.2s ease;

      &:hover {
        box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
        transform: translateY(-2px);
      }
    }

    .title-section {
      margin-left: 10px;
      font-family: "STXihei", "华文细黑", sans-serif;

      .project-name {
        font-size: 18px;
        font-weight: bold;
        color: #333;
      }

      .separator {
        margin: 0 8px;
        color: #606266;
      }

      .function-name {
        font-size: 16px;
        color: #606266;
        font-family: "STKaiti", "楷体", serif;
        letter-spacing: 1px;

        // 水墨效果
        text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1);
      }
    }
  }

  .header-right {
    display: flex;
    align-items: center;

    .user-info {
      display: flex;
      align-items: center;
      cursor: pointer;

      span {
        margin-left: 8px;
        font-family: "STXihei", "华文细黑", sans-serif;
      }
    }
  }
}

.main-container {
  flex: 1;
  overflow: hidden;
  position: relative;
}                                        

.netdisk-aside {
  background-color: transparent;
  height: 100%;                               
  display: flex;
  flex-direction: column;
  border-right: none;
  padding-top: 10px;
  padding: 16px 10px;
  @media screen and (max-width: 768px) {
    position: absolute;
    left: 0;
    top: 0;
    z-index: 100;
    display: none;
  }

  .netdisk-menu {
    border-right: none;
    flex: 1;

    .menu-item,
    .el-sub-menu {
      margin-bottom: 8px;
    }

    .submenu-container {
      background-color: #f7f9fc;
      border-radius: 8px;
      padding: 8px 0;
      overflow: hidden;
    }

    .menu-content {
      background-color: #f5f7fa;
      border-radius: 8px;
      display: flex;
      align-items: center;
      padding-left: 16px;
      height: 100%;
      width: 100%;

      span {
        margin-left: 10px;
      }
    }

    .submenu-content {
      background-color: transparent;
      border-radius: 8px;
      display: flex;
      align-items: center;
      padding-left: 34px;
      padding-right: 16px;
      height: 100%;
      width: 100%;

      span {
        margin-left: 10px;
      }

      &:hover {
        background-color: rgba(53, 120, 229, 0.05);
      }
    }

    :deep(.el-sub-menu__title) {
      height: 50px;
      line-height: 50px;
      font-family: "STXihei", "华文细黑", sans-serif;
      padding: 0 !important;
      margin-bottom: 8px;

      &:hover {
        background-color: transparent;
      }
    }

    :deep(.el-menu-item) {
      height: 50px;
      line-height: 50px;
      font-family: "STXihei", "华文细黑", sans-serif;
      padding: 0 !important;
      border-radius: 8px;

      &:hover {
        background-color: transparent;

        .menu-content {
          background-color: #e9f1ff;
        }
      }

      &.is-active {
        background: transparent;
        color: #333;

        .menu-content {
          background-color: #e9f1ff;
        }
      }
    }

    :deep(.el-menu-item-group__title) {
      padding: 0;
    }

    :deep(.el-menu--inline) {
      background-color: transparent;
      padding: 0;

      .el-menu-item {
        padding-left: 0 !important;
        margin-left: 0;
        margin-right: 0;
        height: 40px;
        line-height: 40px;
        margin-bottom: 2px;
        border-radius: 0;

        &:hover {
          background-color: transparent;
        }

        &.is-active {
          padding-left: 0 !important;

          .submenu-content {
            background-color: #e9f1ff;

            .el-icon,
            span {
              color: #3578e5;
            }
          }
        }
      }
    }

    :deep(.el-icon) {
      font-size: 18px;
      color: #666;
    }

    :deep(.el-sub-menu.is-active) {
      >.el-sub-menu__title {
        .menu-content {
          background-color: #e9f1ff;

          i,
          span {
            color: #3578e5;
          }
        }
      }
    }


  }

  .storage-info-wrapper {
    padding: 16px;
    margin-top: auto;
    border-top: 1px solid #ebeef5;

    .storage-info {
      width: 100%;

      .storage-text {
        display: flex;
        justify-content: center;
        align-items: center;
        margin-top: 8px;
        font-size: 12px;
        color: #606266;

        span {
          font-family: "STXihei", "华文细黑", sans-serif;
        }
      }

      :deep(.el-progress) {
        margin-bottom: 5px;
      }

      :deep(.el-progress__text) {
        font-family: "STXihei", "华文细黑", sans-serif;
        font-size: 12px !important;
      }
    }
  }
}

.netdisk-main {
  background: rgba(243, 246, 250, 1);
  padding: 20px;
  overflow-y: auto;

  // 简约水墨风格背景
  background-image:
    radial-gradient(rgba(0, 0, 0, 0.01) 1px, transparent 1px);
  background-size: 20px 20px;
}
</style>